From: robertlipe Date: Sat, 20 Jun 2015 13:34:46 +0000 (+0000) Subject: Giovanni Zilli adds slope handling to subrip format. X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2~10^2~29 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=56518dfa329bbe4806cbb29572f7537faa4fe024;p=gpsbabel.git Giovanni Zilli adds slope handling to subrip format. --- diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 6a06920db..9a8cf0391 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -867,6 +867,7 @@ double waypt_time(const Waypoint* wpt); double waypt_speed(const Waypoint* A, const Waypoint* B); double waypt_speed_ex(const Waypoint* A, const Waypoint* B); double waypt_vertical_speed(const Waypoint* A, const Waypoint* B); +double waypt_gradient(const Waypoint* A, const Waypoint* B); double waypt_course(const Waypoint* A, const Waypoint* B); double waypt_distance(const Waypoint* A, const Waypoint* B); double waypt_distance_ex(const Waypoint* A, const Waypoint* B); diff --git a/gpsbabel/subrip.cc b/gpsbabel/subrip.cc index 9490aadf4..d4e23a6d4 100644 --- a/gpsbabel/subrip.cc +++ b/gpsbabel/subrip.cc @@ -34,6 +34,7 @@ static int stnum; static gbfile* fout; static const Waypoint* prevwpp; static double vspeed; +static double gradient; /* internal helper functions */ @@ -110,6 +111,9 @@ subrip_prevwp_pr(const Waypoint* waypointp) case 'v': gbfprintf(fout, "%2.2f", vspeed); break; + case 'g': + gbfprintf(fout, "%2.1f%%", gradient); + break; case 't': { QTime t = prevwpp->GetCreationTime().toUTC().time(); @@ -183,6 +187,7 @@ subrip_trkpt_pr(const Waypoint* waypointp) if (prevwpp) { subrip_prevwp_pr(waypointp); vspeed = waypt_vertical_speed(waypointp, prevwpp); + gradient = waypt_gradient(waypointp, prevwpp); } prevwpp = waypointp; } @@ -201,6 +206,7 @@ subrip_wr_init(const char* fname) prevwpp = NULL; vspeed = 0; + gradient = 0; if ((opt_gpstime != NULL) && (opt_gpsdate != NULL)) { time(&gpstime_t); diff --git a/gpsbabel/waypt.cc b/gpsbabel/waypt.cc index 15706c5a1..93c60b4c8 100644 --- a/gpsbabel/waypt.cc +++ b/gpsbabel/waypt.cc @@ -564,6 +564,29 @@ waypt_vertical_speed(const Waypoint* A, const Waypoint* B) } } +/* + * Returns "Road Gradient" between A and B as a percentage of slope. + * If there is no distance or either A or B have unknown altitude, return 0. + */ +double +waypt_gradient(const Waypoint* A, const Waypoint* B) +{ + double dist, altitude, gradient; + dist = waypt_distance(A, B); + if (dist == 0) { + return 0; + } + + altitude = A->altitude - B->altitude; + if (altitude == 0 || + A->altitude == unknown _alt || B->altitude == unknown_alt) { + return 0; + } + + gradient = (altitude / dist) * 100; + return (gradient); +} + /* * Calculates "Course True" from A to B */ diff --git a/gpsbabel/xmldoc/formats/options/subrip-format.xml b/gpsbabel/xmldoc/formats/options/subrip-format.xml index 1d017a678..c6f1054e5 100644 --- a/gpsbabel/xmldoc/formats/options/subrip-format.xml +++ b/gpsbabel/xmldoc/formats/options/subrip-format.xml @@ -39,6 +39,10 @@ %h heart rate + + %g + road gradient + \n newline